*****************************************************************
*****************************************************************
*** 0. General settings
*****************************************************************
*****************************************************************

* clear
clear
clear 		mata
mat 		drop _all

* set path
global		path	""					


* load balance sheet data 
	**********************************+

	use "$path/0 Data/_Processed/BHC_Bank_Ratios.dta", clear

merge m:m entity using "$path/0 Data/_Processed/sample"
keep if _merge == 3
drop _merge

	tsset entity yq
	sort entity yq

	by entity: gen unused_ci = offbs_unused_loans / assets_total
	by entity: gen wholesale = wholesale_funding / assets_total


	drop if unused_ci == .

	egen group = group(entity)
	sum group
	collapse (mean) unused_ci wholesale liquidity_risk [aweight= assets_total],by(yq)
	tsset yq



	* a) Figure 2 Panel B. Components of liquidity risk 
	**********************************************************

		twoway (tsline unused_ci) (tsline wholesale, yaxis(2)), ///
		scheme(s2mono) ///
		xtitle("Date") 		///
		ytitle("Unused C&I Credit Lines (% Total Assets)") ytitle("Wholesale Funding (% Total Assets)", axis(2)) ///
		legend(label(1 "Unused C&I Credit Lines") label(2 "Wholesale Funding")) ///
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 

		graph export "$path/05 Figures/Figure 2 Panel A.png", as(png) name("Graph") replace


	* b) Figure 2 Panel A. Liquidity risk 
	**************************************************

		tsline liquidity_risk, ///
		scheme(s2mono) ///
		xtitle("Date") 	xline(21997)	///
		ytitle("Liquidity Risk") ///
		legend(off) ///
		graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) 

		graph export "$path/05 Figures/Figure 2 Panel B.png", as(png) name("Graph") replace
		